#coding=utf-8
import requests
import json

# 引入自定义的keystone模块
import keystone
keystone_s=keystone.getToken()

#nova(compute)端点地址：
flavors_url="http://192.168.100.10:8774/v2.1/flavors"
#定义请求头
headers={
    "X-Auth-Token":keystone_s['token'],
    "Content-Type": "application/json"
}
body={
	"flavor": {
        "id": "10",
		"name": "132",
		"ram": 1024,
		"vcpus": 2,
		"disk": 10,
		"rxtx_factor": 2
	}
}
#发送请求
req=requests.post(flavors_url,headers=headers,data=json.dumps(body))
#格式化打印相应
print(json.dumps(req.json(),sort_keys=True,indent=4))
print(req.status_code)
if (req.status_code==200):
    print("创建成功")
else:
    print("创建失败")